package com.lagou.sort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SortReducer extends Reducer<IntWritable,IntWritable,IntWritable,IntWritable> {

    private static IntWritable linesum = new IntWritable(1);
    @Override
    protected void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        for(IntWritable v:values){
            //linesum作为key，key作为value的值
            context.write(linesum,key);
            //linesum自增
            linesum = new IntWritable(linesum.get()+1);
        }
    }
}
